package cn.hs.ph.dao.impl;

import cn.hs.ph.dao.UserDao;
import cn.hs.ph.entity.User;
import cn.hs.ph.util.JDBCDruidUtil;

import java.sql.ResultSet;
import java.sql.SQLException;

public class UserDaoImpl implements UserDao {
    @Override
    public User selectByUsernameAndPwd(String username, String pwd) {
        String sql="select * from user where username=? and pwd=?";
        Object obj[]={username,pwd};
        ResultSet res = JDBCDruidUtil.query(sql, obj);
        User user=null;
        while (true) {
            try {
                if (!res.next()) break;
                user=new User(res.getInt(1),res.getString(2),res.getString(3));
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }
        JDBCDruidUtil.close();
        return user;
    }
}
